package com.ruoyi.web.sso.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.web.sso.common.util.AssertUtil;
import com.ruoyi.web.sso.common.util.UuidUtil;
import com.ruoyi.web.sso.util.CopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.sso.mapper.AllianceMapper;
import com.ruoyi.web.sso.domain.Alliance;
import com.ruoyi.web.sso.service.IAllianceService;
import com.ruoyi.common.core.text.Convert;

/**
 * 加盟信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-01-08
 */
@Service
public class AllianceServiceImpl implements IAllianceService 
{
    @Autowired
    private AllianceMapper allianceMapper;

    /**
     * 查询加盟信息
     * 
     * @param id 加盟信息主键
     * @return 加盟信息
     */
    @Override
    public Alliance selectAllianceById(String id)
    {
        return allianceMapper.selectAllianceById(id);
    }

    /**
     * 查询加盟信息列表
     * 
     * @param alliance 加盟信息
     * @return 加盟信息
     */
    @Override
    public List<Alliance> selectAllianceList(Alliance alliance)
    {
        return allianceMapper.selectAllianceList(alliance);
    }

    /**
     * 新增加盟信息
     * 
     * @param alliance 加盟信息
     * @return 结果
     */
    @Override
    public int insertAlliance(Alliance alliance)
    {
        alliance.setId(UuidUtil.getUuid());
        alliance.setCreateTime(DateUtils.getNowDate());
        return allianceMapper.insertAlliance(alliance);
    }

    /**
     * 修改加盟信息
     * 
     * @param alliance 加盟信息
     * @return 结果
     */
    @Override
    public int updateAlliance(Alliance alliance)
    {
        alliance.setUpdateTime(DateUtils.getNowDate());
        return allianceMapper.updateAlliance(alliance);
    }

    @Override
    public int insertAndUpdateAlliance(Alliance alliance) {
        Alliance alliance1 = allianceMapper.getPhone(alliance.getPhone());
        if (AssertUtil.isEmpty(alliance1)){
            alliance.setId(UuidUtil.getUuid());
            alliance.setCreateTime(DateUtils.getNowDate());
            return allianceMapper.insertAlliance(alliance);
        }else {
            alliance1.setUpdateTime(DateUtils.getNowDate());
            CopyUtils.copyProperties(alliance1,alliance);
            return allianceMapper.updateAlliance(alliance);
        }
    }

    /**
     * 批量删除加盟信息
     * 
     * @param ids 需要删除的加盟信息主键
     * @return 结果
     */
    @Override
    public int deleteAllianceByIds(String ids)
    {
        return allianceMapper.deleteAllianceByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除加盟信息信息
     * 
     * @param id 加盟信息主键
     * @return 结果
     */
    @Override
    public int deleteAllianceById(String id)
    {
        return allianceMapper.deleteAllianceById(id);
    }
}
